package cn.com.server.common.util;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

public class ExceptionUtil{
	
	public static String exceptionToString(Exception exception) {
		StringWriter sw = null;
		PrintWriter pw = null;
		try {
			sw = new StringWriter();
			pw = new PrintWriter(sw);
			exception.printStackTrace(pw);
			String es = sw.toString();
			if (pw != null) {
				pw.close();
			}
			if (sw != null) {
				sw.close();
			}
			return es;
		} catch (Exception e) {
			if (pw != null) {
				pw.close();
			}
			if (sw != null) {
				try {
					sw.close();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
			return "ErrorInfoFromException";
		} 
	}
}
